package krt.wid.gslzs.util;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

/**
 * Created by admin on 2018/5/9.
 */

public class TestAdapter extends BaseAdapter {
    List<Test> mData;

    public TestAdapter(List<Test> data){
            this.mData =  data;
    }
    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int i) {
        return mData.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
            if(view ==null) {
                view = LayoutInflater.from(viewGroup.getContext()).inflate(android.R.layout.simple_spinner_dropdown_item, viewGroup, false);
            }

            view.setSelected(mData.get(i).isSelected);

            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                        view.setSelected(!view.isSelected());
                        notifyDataSetChanged();
                }
            });

        return null;
    }

    public class  Test{
        private String title;
        private boolean isSelected;

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public boolean isSelected() {
            return isSelected;
        }

        public void setSelected(boolean selected) {
            isSelected = selected;
        }
    }
}
